﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package ZLocalization.Substituters {

    public class SubstituterContractions extends SubstituterSimple {

        protected static var contractionMap:Object = {};

        override public function replace(_arg1:String, _arg2:Object):String{
            var _local3:String;
            var _local4:String;
            var _local5:RegExp;
            var _local6:Array;
            var _local7:String;
            var _local8:String;
            var _local9:Object;
            var _local10:Object;
            var _local11:String;
            var _local12:Object;
            var _local13:String;
            var _local14:String;
            for (_local3 in _arg2) {
                _local4 = _arg2[_local3];
                _local5 = this.getContractionPattern();
                _local6 = _local4.match(_local5);
                if (_local6){
                    _local7 = _local6[1];
                    _local8 = _local4.replace(new RegExp(("^" + _local7)), "");
                    _local7 = _local7.toLowerCase();
                    _local9 = this.getContractionMap();
                    _local10 = _local9[_local7];
                    for (_local11 in _local10) {
                        _local12 = _local9[_local7][_local11];
                        _local13 = this.getContraction(_local12, _local8);
                        if (_local13.substr(-1, 1) == "'"){
                            _local14 = ((" " + _local13) + _local8);
                        } else {
                            _local14 = (((" " + _local13) + " ") + _local8);
                        };
                        _arg1 = _arg1.replace(new RegExp((((("^" + _local11) + " {") + _local3) + "}")), _local14);
                        _arg1 = _arg1.replace(new RegExp(((((" " + _local11) + " {") + _local3) + "}"), "g"), _local14);
                    };
                };
                _arg1 = _arg1.replace(new RegExp((("{" + _local3) + "}"), "g"), _local4);
            };
            return (_arg1);
        }
        protected function getContractionMap():Object{
            return (SubstituterContractions.contractionMap);
        }
        protected function getContractionPattern():RegExp{
            var _local3:String;
            var _local4:RegExp;
            var _local1:Object = this.getContractionMap();
            var _local2 = "";
            for (_local3 in _local1) {
                if (_local3.charAt((_local3.length - 1)) != "'"){
                    _local2 = (_local2 + (_local3 + " |"));
                } else {
                    _local2 = (_local2 + (_local3 + "|"));
                };
            };
            _local2 = _local2.substr(0, (_local2.length - 1));
            _local4 = new RegExp((("^(" + _local2) + ")"), "i");
            return (_local4);
        }
        protected function getContraction(_arg1:Object, _arg2:String):String{
            if (typeof(_arg1) == "string"){
                return (String(_arg1));
            };
            return ("");
        }

    }
}//package ZLocalization.Substituters 
